package com.yoyo.common.utils;

import com.yoyo.common.core.domain.entity.SysUser;
import com.yoyo.common.utils.bean.BeanUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;

/**
 * @author zyl
 * @Date 2021/6/27 -15:05
 */
public class ShiroUtils {

    public static Session getSession() {
        return SecurityUtils.getSubject().getSession();
    }


    public static Subject getSubject() {
        return SecurityUtils.getSubject();
    }

    public static String getIp() {
        return getSubject().getSession().getHost();
    }

    public static SysUser getSysUser() {
        SysUser user = null;
        Object obj = getSubject().getPrincipal();
        if (StringUtils.isNotNull(obj)) {
            user = new SysUser();
            BeanUtils.copyBeanProp(user, obj);
        }
        return user;
    }
}
